using System;
using System.Collections.Generic;
using System.Text;
using GameFramework;

namespace Projet_X0
{
    public class Collidable : State
    {
        private BoundingBox boundingBox = null;
        private Entity owner = null;
        
        public Collidable(Entity owner)
            : base((int)StatesID.Collidable)
        {
            boundingBox = new BoundingBox();
            this.owner = owner;
            
        }

        public Collidable GetCollidable()
        {
            boundingBox.Set(owner.getForm().getBoundingBox());
            
            return this;
        }

        public List<Entity> GetCollisions()
        {
            List<Entity> collisions = new List<Entity>();
            Collidable collidable = null;
            List<Entity> entities = GameManager.GetCurrent().GetEntities();
            
            for(int i=0;i<entities.Count;i++)
            {
                collidable = (Collidable)entities[i].GetState((int)StatesID.Collidable);

                if (entities[i] == owner || entities[i].GetID() == (int)EntityID.Projectile)
                    continue;
                
                if (collidable != null)
                {
                    if(boundingBox.HasCollided(collidable.GetBoundingBox()))
                        collisions.Add(entities[i]);
                }
                
            }

            return collisions;
        }

        public BoundingBox GetBoundingBox()
        {
            return boundingBox;
        }
        
        public override void Terminate()
        {
            boundingBox = null;
        }
    }
}
